﻿var numbers = new List<int>()
{
    1, 3, 2, 34, 5, 4
};


int value = GetFirstElement(numbers);
Console.WriteLine(value);

Console.ReadKey();

int GetFirstElement(IEnumerable<int> numbers)
{
    foreach (var number in numbers)
    {
        return number;
    }

    throw new InvalidOperationException("The collection cannot be empty.");
}


bool IsFirstElementPositive(IEnumerable<int> numbers)
{
    try
    {
        var firstElement = GetFirstElement(numbers);
        return firstElement > 0;
    }
    catch (InvalidOperationException ex)
    {
        Console.WriteLine("The collection is empty!");
        return true;
    }
    catch (NullReferenceException ex)
    {
        throw new ArgumentNullException("The collection is null.", ex);
    }
}

Console.ReadKey();

[Serializable]
public class CustomException : Exception
{
    public  int StatusCode { get; }
    
    public CustomException()
    {
    }

    public CustomException(string message):base(message)
    {
        
    }
    public CustomException(string message, Exception innerException)
        : base(message, innerException)
    {
    }
}